package com.example.tiku7.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tiku7.Bean;
import com.example.tiku7.R;
import com.example.tiku7.Recy_Adapter;
import com.example.tiku7.net.View_Mian;
import com.example.tiku7.p.Presenter;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.annotations.NonNull;


/**
 * A simple {@link Fragment} subclass.
 */
public class AFragment extends Fragment implements View_Mian {


    private RecyclerView mRecy;
    private ArrayList<Bean.ResultsBean> beanli;
    private Recy_Adapter madapter;

    public AFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View inflate = inflater.inflate(R.layout.fragment_a, container, false);
        Presenter presenter = new Presenter(this);
        presenter.getData();
        initView(inflate);
        return inflate;
    }

    private void initView(@NonNull final View itemView) {
        mRecy = (RecyclerView) itemView.findViewById(R.id.recy);
        mRecy.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecy.addItemDecoration(new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL));
        beanli = new ArrayList<>();
        madapter = new Recy_Adapter(beanli, getActivity());
        mRecy.setAdapter(madapter);


    }

    @Override
    public void showbean(List<Bean.ResultsBean> beanList) {
        beanli.addAll(beanList);
        madapter.notifyDataSetChanged();
    }

    @Override
    public void showToast(String str) {
        Toast.makeText(getActivity(), "str", Toast.LENGTH_SHORT).show();
    }
}
